<?php require_once('Connections/myconnect.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['txttaikhoan'])) {
  $loginUsername=$_POST['txttaikhoan'];
  $password=$_POST['txtmatkhau'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "index.php";
  $MM_redirectLoginFailed = "Dangnhap.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_myconnect, $myconnect);
  
  $LoginRS__query=sprintf("SELECT TenDN, MatKhau FROM thanhvien WHERE TenDN=%s AND MatKhau=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $myconnect) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<link rel="stylesheet" type="text/css" href="CSS/style-login.css">
<style type="text/css">
<!--
#apDiv1 {
	position:absolute;
	left:204px;
	top:148px;
	width:349px;
	height:196px;
	z-index:1;
}
#apDiv2 {
	position:absolute;
	left:199px;
	top:141px;
	width:359px;
	height:206px;
	z-index:1;
}
.style1 {color: #FFFFFF}
#apDiv2 #form1 #btdangnhap {
	color: #FFFFFF;
}
#apDiv2 #form1 #btdangnhap {
	background-color: #FFFFFF;
}
#footer .style2 {
}
#apDiv2 #form1 #btdangnhap {
	background-color:#fa476b;
}
.style2 {color: #999999}
.style4 {color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; }
.style5 {font-family: Arial, Helvetica, sans-serif}
-->
</style>
</head>

<body>
<div id="apDiv2">
  <form ACTION="<?php echo $loginFormAction; ?>" id="form1" name="form1" method="POST">
    <table width="354" border="0">
      <tr>
        <td width="348" class="style4">Bạn chưa có tài khoản ? |<a href="Dangki.php">Đăng kí mới tại đây!</a></td>
      </tr>
      <tr>
        <td height="23"><span class="style4"><strong>Tài khoản:</strong></span></td>
      </tr>
      <tr>
        <td><input name="txttaikhoan" type="text" id="txttaikhoan" /></td>
      </tr>
      <tr>
        <td><span class="style4"><strong>Mật khẩu:</strong></span></td>
      </tr>
      <tr>
        <td><input name="txtmatkhau" type="password" id="txtmatkhau" /></td>
      </tr>
      <tr>
        <td><div align="justify" class="style5">
            <span class="style1">
          <input type="checkbox" name="cbxduytritrangthaidangnhap" id="cbxduytritrangthaidangnhap" />
        Duy trì trạng thái đăng nhập <br/><a href="Laylaimatkhau.php">Quên mật khẩu</a></strong></span></div></td>
      </tr>
      <tr>
        <td><input type="submit" name="btdangnhap" id="btdangnhap" value="Đăngnhập" /></td>
      </tr>
    </table>
    
    
  </form>
</div>
<div id="header">
  
</div>
<div id="content">
</div>
            
            
<div id="footer">
	
          
  <div align="center">
    <p align="center" class="style2">Để tham gia phiên bản thử nghiệm</p>
    <p align="center" class="style2">Bạn cần đăng kí mới</p>
  </div>
</div>
    
</body>
</html>
